package com.chinasoft.back.controller;

import com.auth0.jwt.interfaces.Claim;
import com.chinasoft.back.pojo.Result;
import com.chinasoft.back.pojo.User;
import com.chinasoft.back.service.UserService;
import com.chinasoft.back.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 中软zhang
 * @create 2023-08-28 14:04
 */
@RestController
@CrossOrigin  // 支持跨域
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/api/login")
    public Result<String> doLogin(User user) {
        Result<String> ret ;
        ret = userService.login(user);
        System.out.println(ret);
        return ret;
    }

    // 获取用户信息
    @GetMapping("/my/userinfo")
    public Result<User> getUserInfo(HttpServletRequest request) {

        // 获取拦截器传递的用户信息
        User user = (User) request.getAttribute("user");
//        System.out.println(token);
        Result<User> result = new Result<>();
        result.setStatus(0);
        result.setMessage("success");
        result.setData(user);
        return result;
    }
}